import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/material.dart';
import '../../utils/Global.dart';
import 'HomeSwiper.dart';
import 'HomeCourse.dart';

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  List swiperList = [];
  List courseList = [];
  @override
    void initState() {
      // 获取轮播图
      G.api.ad.getAdList().then((res){
        setState(() {
          swiperList = res.where((item) => item['status'] == 1).toList();     
        });
        print(res);
      });

      // 获取课程列表
      G.api.course.getCourseList().then((res) {
        setState(() {
          courseList = res;          
        });
      });
      super.initState();
    }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.grey[200],
      child: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Container(
              height: 400.h,
              child: HomeSwiper(adList: swiperList),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.all(10),
            sliver: HomeCourse(courseList: courseList),
          ),
        ],
      ),
    );
  }


  @override
    void dispose() {
      super.dispose();
    }
}